package com.antxon.cliente;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class ClienteAction extends ActionSupport implements ModelDriven<Cliente> {

	private static final long serialVersionUID = -6659354552584240539L;

	
	private Cliente cliente = new Cliente();
	private List<Cliente> listaClientes = new ArrayList<Cliente>();
	private ClienteDAO clienteDAO = new ClienteDAO();

	
	@Override
	public Cliente getModel() {
		return cliente;
	}
	
	/**
	 * To save or update user.
	 * @return String
	 */
	public String guardarOActualizar()
	{	
		clienteDAO.guardarOActualizarCliente(cliente);
		return SUCCESS;
	}
	
	/**
	 * Nuevo personaje
	 * @return String
	 */
	public String nuevo()
	{
		return SUCCESS;
	}
	
	/**
	 * lista todos los personajes.
	 * @return String
	 */
	public String listar()
	{
		listaClientes = clienteDAO.listarClientes();
		return SUCCESS;
	}
	
	/**
	 * carga el formulario casas
	 * @return String
	 */
	public String clientes()
	{
		return SUCCESS;
	}

	
	
	/**
	 * To delete a user.
	 * @return String
	 */
	public String eliminar()
	{
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		clienteDAO.eliminarCliente(Long.parseLong(request.getParameter("id")));
		return SUCCESS;
	}
	
	
	
	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public List<Cliente> getListaClientes() {
		return listaClientes;
	}

	public void setListaClientes(List<Cliente> listaC) {
		this.listaClientes = listaC;
	}
	


}
